<?php

namespace App\Models;

use App\Models\Rbac\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class JobType extends BaseModel
{
    use HasFactory;
    protected $table = 'job_type';
    // 允许批量操作的字段
    protected $fillable = ['job_type','sort','is_part','is_multi','multi_order_num','is_restrict','is_del','print_num','created_at','updated_at'];

    public function scopeSearch($query,$params)
    {
        if(!empty($params['job_type'])){
            $query->where('job_type','like','%'.$params['job_type'].'%');
        }
        if(!empty($params['is_part'])){
            $query->where('is_part',$params['is_part']??1);
        }
        $query->where('is_del',$params['is_del']??2);
        return $query;
    }

    public function user(){
        return $this->belongsToMany(User::class,'employee','job_type_id','user_id')->with('employee');
    }
    public function employee(){
        return $this->belongsTo(Employee::class,'id','job_type_id');
    }
}
